<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://www.longtop.com/intelliweb" prefix="e"%>
<%@page isELIgnored="false"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>考核体系关联指标</title>
	</head>
	<e:View id="eView" designProperty="width: 1024; height: 768">
		<script type="text/javascript"
			src="${pageContext.request.contextPath}/js/perform/perform.js"></script>
		<div id="Invisual Controls" style="min-height: 40px; background-color: LemonChiffon;">
			<e:Dataset id="Dateset_SystemClass" pageSize="-1"  datasetDefinition="DatasetDefinition_sys.dsd" datasetRef="dataset">
				 <e:Field name="classId" dataType="string" label="classId" maxLength="32"  required="true"/>
				 <e:Field name="systemId" dataType="string" label="systemId" maxLength="32" />
				 <e:Field name="parentClassId" dataType="string" label="parentClassId" maxLength="32" />
				 <e:Field name="className" dataType="string" label="className" maxLength="100"  required="true"/>
				 <e:Field name="classDesc" dataType="string" label="classDesc" maxLength="200" />
				 <e:Field name="remark" dataType="string" label="remark" maxLength="400" />
			</e:Dataset>
			<e:Dataset id="Dateset_SystemClassIndex" datasetDefinition="DatasetDefinition_sys.dsd" datasetRef="dataset">
				<e:Field name="indexName" dataType="string" label="indexName" maxLength="" />
				<e:Field name="indexId" dataType="string" label="indexId" maxLength="32" />
			</e:Dataset>
			<e:Command id="Command_save" action="com.longtop.perform.zb.system.web.SystemClassEditAction" method="saveSystemClass" showHintInfoOnSuccess="false" onExecuteSuccess="Save_OnExecuteSuccess()">
				<e:DatasetInfo name="DatasetInfo1" dataset="Dateset_SystemClass"></e:DatasetInfo>
				<e:DatasetInfo name="DatasetInfo2" dataset="Dateset_SystemClassIndex" submitType="all"></e:DatasetInfo>
			</e:Command>
			<e:LookupDropDown id="LookupDropDown_index" path="/jsp/perform/zb/index/indexDropdown.jsp"	windowWidth="600" windowHeight="370" 
					autoDropDown="true" fixed="true" onSelect="LookupDropDown_Index_onSelect(dropdown,iframe,text)" windowCaption="选择指标">
			</e:LookupDropDown>
		</div>
		<body style="height: 362px">
			<e:Page id="ePage"
				action="com.longtop.perform.zb.system.web.SystemClassEditAction"
				onAfterLoadPage="ePage_onAfterLoadPage()" onBeforeLoadPage="ePage_onBeforeLoadPage()" style="height: 348px">
				<table border="0" width="100%" height="100%" cellpadding="1" cellspacing="1" style="height: 308px">
					<tr>
						<td>
							<div style="widh:100%;height:315px;overflow:auto;">
								<table border="0" cellpadding="1" cellspacing="1" width="98%">
									<tbody valign="top">
										<tr>
													<td align="center" colspan="4" >
														<e:Button id="Button_Save" caption="保存" style="width: 70px; height: 22px" onClick="Button_Save_onClick()" icon="/images/submit.gif"></e:Button>&nbsp;&nbsp;
													</td>
										</tr>	
										<tr>
												<td width="120px">
													<e:Label id="Label_classId" caption="分类Id"></e:Label>
												</td>
												<td>
													<e:Text id="classId" dataset="Dateset_SystemClass"
															field="classId" style="width: 450px"></e:Text>
												</td>
										</tr>
										<tr>
												<td width="120px">
													<e:Label id="Label_className" caption="分类名称"></e:Label>
												</td>
												<td>
														<e:Text id="className" dataset="Dateset_SystemClass"
															field="className" style="width: 450px"></e:Text>
												</td>
										</tr>
										<tr>
											<td>
												<e:Label id="Label_classDesc" caption="分类说明"></e:Label>
											</td>
											<td>
												<e:Text id="classDesc" dataset="Dateset_SystemClass"
													field="classDesc" editorType="textarea"
													style="width: 450px; height: 40px;"></e:Text>
											</td>
										</tr>
										<tr>
											<td>
												<e:Label id="Label_remark" caption="备注"></e:Label>
											</td>
											<td>
												<e:Text id="remark" dataset="Dateset_SystemClass"
													field="remark" editorType="textarea"
													style="width: 450px; height: 40px;"></e:Text>
											</td>
										</tr>
										<tr>
							              <td width="120px">
							              		<e:Label id="Label_index" caption="关联指标"></e:Label>
							              </td>
							              <td>
							                <table height="100%" cellpadding="0" cellspacing="0"><tr>
							                  <td>
							                    <select id="select" size="8" multiple style="width:300px;"></select>
							                  </td><td>
							                    &nbsp;<e:Button id="Button_add" caption="添加指标" style="width:80px" onClick="Button_add_onClick()" /><br><br>
							                    &nbsp;<e:Button id="Button_del" caption="删除指标" style="width:80px" onClick="Button_del_onClick()" /><br><br>
							                    &nbsp;<e:Button id="Button_delAll" caption="删除所有指标" style="width:80px" onClick="Button_delAll_onClick()" />
							                  </td>
							                  <td align="right">
							                  </td>
							                </tr></table>
							              </td>
							            </tr>
									</tbody>
								</table>
							</div>
						</td>
					</tr>
				</table>
			</e:Page>
		</body>
		<script type="text/javascript">
			//增加指标
			function Button_add_onClick(){
				var lookup=$J("LookupDropDown_index").open();
			}
			
			function LookupDropDown_Index_onSelect(dropdown,iframe,text){
				var dataset = $J("Dateset_SystemClassIndex");
			    var dataset_coll = $J("Dateset_SystemClass");
			    var classRecord=dataset_coll.getCurrentRecord();
			    var select = document.getElementById("select");
			    var datasetZbIndex = $J(iframe.Dataset_Index);
			    var allowInsert;
			    var code,name;
			    var record;
			    if(dataset){//除去根节点
				   var getrecords = datasetZbIndex.getSelectedRecords();
				   for(var i=0;i<getrecords.length;i++){
				   	   getrecord=getrecords[i];
					   if(typeof getrecord != "undefined" && getrecord != null){
				       code = getrecord.getValue("indexId");
				       name = getrecord.getValue("indexName");
				       allowInsert = addOption(select, name , code);
				       if (!allowInsert){
				           record = dataset.insertRecord();
				           record.setValue("indexId",code);
				            if(classRecord.state!='1'){
						    	 classRecord.state =2;
						    }
				        }
				        }
				   }
				   
			    }
			    
			}
			
			function ePage_onAfterLoadPage(){	
			if(!isEmpty($J("classId").getValue())){
				$J("classId").setReadOnly(true);
			}
			var datasetss = $J("Dateset_SystemClass");
				var classRecord=datasetss.getCurrentRecord();
			var dataset = $J("Dateset_SystemClassIndex");
			var select=document.getElementById("select");
			var list=dataset.records;
			for(var i=0;i<list.length;i++){
				var record=list.get(i);
				var code=record.getValue("indexId");
				var name=record.getValue("indexName");
				addOption(select, name , code);
				}
			}
			
			//删除指标
			function Button_del_onClick(){
			    var dataset = $J("Dateset_SystemClassIndex");
			    var dataset_coll = $J("Dateset_SystemClass");
			    var select = document.getElementById("select");
				var len = select.options.length;
			    if (select.length != 0){
			        for(var i=len;i>0 ; i--){
			            if (select.options[i-1].selected && select.selectedIndex != -1){
			                var record = dataset.locate(["indexId"],[select.options[i-1].value]);
			                if(record != null){
			                	if(len > 1){
					 				len = len -1;
					 			}else{
					 				len = 0;
						 		}
			                    dataset.setRecord(record);
			                    deleteIndicatorInSet(record);
			                }
			            }
			        }
			    }
			}
			
			function deleteIndicatorInSet(record){
			    var dataset = $J("Dateset_SystemClassIndex");
			    dataset.setRecord(record);
			    record.state = 3;
			    
			    //设置该记录为修改
			    var dataset_coll = $J("Dateset_SystemClass");
			    var classRecord=dataset_coll.getCurrentRecord();
			    if(classRecord.state!='1'){
			    	classRecord.state =2;
			    }
			    var select = document.getElementById("select");
			    var len = select.options.length;
			    for (var i=len;i>0 ; i--){
			        if(select.options[i-1].value == record.getValue("indexId")){
			            select.options.remove(i-1);
			            if(len > 1){
					 		len = len -1;
					 	}else{
					 		len = 0;
						}
			        }
			    }
			}
			//删除所有指标
			function deleteAllIndicator(){
			    var dataset = $J("Dateset_SystemClassIndex");
			    var dataset_coll = $J("Dateset_SystemClass");
			    var select = document.getElementById("select");
			    if (select.length != 0){
			        select.options.length = 0;
			        var record = dataset.getFirstRecord();
			        while(record != null){
			            record.state =3;
			            record = record.getNextRecord();
			        }
			    }
			}
			//删除所有指标
			function Button_delAll_onClick(){
			    var ds_indicatorSet = $J("Dateset_SystemClass");
			    MsgBox.showConfirmMsg("确定要删除集合 ["+ds_indicatorSet.getValue('className')+"] 中的所有删除指标吗?","确定",[deleteAllIndicator],[cancelDel]);
			}
			function cancelDel(){
			}
			//保存指标分类
			function Button_Save_onClick(){
				var dataset = $J("Dateset_SystemClass");
				var classRecord=dataset.getCurrentRecord();
			    Command_save.execute();
			}
			function Save_OnExecuteSuccess(){
				alert("保存成功");
				parent.location.reload();
			}
		</script>
	</e:View>
</html>
